package com.suxin.pool;

import lombok.SneakyThrows;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Tang
 * @classname ThreadPool
 * @description [  ]
 * @date 2021/3/10 14:47
 */
public class ThreadPool {

    @SneakyThrows
    public static void main(String[] args) {

        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(1,2,3L, TimeUnit.MICROSECONDS,
                new ArrayBlockingQueue<>(2));

        for (int i = 0; i < 6; i++) {
            int finalI = i;
            poolExecutor.execute(() -> {
                System.out.println("----" + finalI);
            });
            TimeUnit.SECONDS.sleep(1);
        }

        System.out.println("end....");

        System.out.println(poolExecutor.getQueue().isEmpty());

        poolExecutor.shutdown();
    }

}